﻿new Vue({
    el: "#divUser",
    data: {
        search: {
            pageIndex: 1,
            pageSize: 10,
            name: '',
            loginName: '',
            statusType: ''
        },
        loading: false,
        user: {
            list: [],
            total: 0
        },
        statusTypeList: [
            { id: 1, name: "启用" },
            { id: 2, name: "禁用" }
        ],
        dialog: {
            title: '添加用户',
            form: {
                id: 0,
                statusType: 1,
                name: '',
                loginName: '',
                remark: ''
            },
            show: false
        },
        rules: {
            name: [
                { required: true, message: '请输入姓名', trigger: 'blur' }
            ],
            loginName: [
                { required: true, message: '请输入账号', trigger: 'blur' },
                { min: 11, max: 11, message: '请输入正确的手机号', trigger: 'blur' }
            ],
            statusType: [
                { required: true, message: '请选择状态', trigger: 'change' }
            ]
        }
    },
    mounted: function () {
        VmTop.navOn = 4;
        //加载列表数据
        this.getList();

    },
    methods: {
        //搜索按钮
        openDialog: function (row) {
            if (row == undefined) {
                this.dialog = {
                    title: '添加用户信息',
                    form: {
                        id: 0,
                        statusType: 1,
                        name: '',
                        loginName: '',
                        remark: ''
                    },
                    show: true
                };
            }
            else {
                this.dialog = {
                    title: '修改用户信息',
                    form: {
                        id: row.id,
                        statusType: row.statusType,
                        name: row.name,
                        loginName: row.loginName,
                        remark: row.remark
                    },
                    show: true
                };
            }
        },
        //列表属性转换
        formatDate: function (row, col, value) {
            return value.split(" ")[0];
        },
        ///跳转页面时
        pageChange: function (page) {
            this.search.pageIndex = page;
            //加载列表数据
            this.getList();
        },
        //查询公告活动动态
        getList: function () {
            var that = this;
            that.loading = true;
            $.getJSON("/user/getList", that.search, function (result) {
                that.user = result;
                that.loading = false;
            });
        },
        saveUser: function () {
            var that = this;
            this.$refs["dialog.form"].validate(function (valid) {
                if (valid) {
                    that.loading = true;
                    $.post("/user/Save", that.dialog.form, function (res) {
                        VmYz.message(res.msg, res.suc);
                        if (res.suc) {
                            that.getList();
                            that.dialog.show = false;
                        }
                    });
                }
            });
        },
        //删除
        delUser: function (id) {
            that = this;
            VmYz.confirm("确定要删除此用户吗?", function () {
                $.post("/user/delete", { id: id },
                    function (result) {
                        if (result.suc) {
                            //加载列表数据
                            that.getList();
                        }
                        VmYz.message(result.msg, result.suc);
                    });
            })
        },
        resetPwd: function (id) {
            that = this;
            VmYz.confirm("确定要重置此用户密码吗?", function () {
                $.post("/user/RetSetPwd", { id: id },
                    function (result) { 
                        VmYz.message(result.msg, result.suc);
                    });
            })
        }
    }
})